﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Core;

namespace Web.Controllers
{
    public class statusController : JsonController
    {
        //
        // GET: /status/

        public ActionResult getStatus(int rid)
        {
            return Json(status.getStatus(rid, Certify.username, Certify.god));
        }

        public ActionResult getStatusList(int start, int limit, int? pid, string username, string school, int? lang, int? status)
        {
            return Json(Core.status.getStatusList(start, limit, Certify.username, Certify.god, pid, username.ToQ(), school.ToQ(), lang, status));
        }

        [OnlyGod]
        public ActionResult deleteStatus(int rid)
        {
            return Json(status.deleteStatus(rid));
        }

        [OnlyGod]
        public ActionResult rejudgeStatus(int rid)
        {
            return Json(status.rejudgeStatus(rid));
        }

        [OnlyGod]
        public ActionResult getTestStatus(int rid)
        {
            return Json(status.getTestStatus(rid));
        }

        [ValidateInput(false)]
        [NeedLogon]
        [ParamsNoEmpty]
        public ActionResult submitCode(int pid, int lang, string code)
        {
            return Json(status.submitCode(pid, lang, code, Certify.username, Certify.god));
        }

        [NeedLogon]
        public ActionResult getCode(int rid)
        {
            return Json(status.getCode(rid, Certify.username, Certify.god));
        }

        [Myself]
        public ActionResult inquiryBackupCode(string username, string allDate, string dateBegin, string dateEnd)
        {
            CheckEmpty(username);
            var _allDate = allDate.ToBool();
            if (!_allDate) CheckWhite(dateBegin, dateEnd);
            return Json(status.inquiryBackupCode(username, _allDate, CheckDateQ(dateBegin), CheckDateQ(dateEnd)));
        }

        [Myself]
        public ActionResult getBackupCode(string username, string allDate, string dateBegin, string dateEnd)
        {
            CheckEmpty(username);
            var _allDate = allDate.ToBool();
            if (_allDate) CheckWhite(dateBegin, dateEnd);
            return View();
        }
    }
}
